package com.qingcloud.df.executor.engine;

import com.qingcloud.df.executor.launcher.Launcher;
import com.qingcloud.df.sdk.component.context.CompInstContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class ExecuteEngine {
    Logger logger  = LoggerFactory.getLogger(ExecuteEngine.class);

    private Launcher launcher;

    public Launcher getLauncher() {
        return launcher;
    }
    public void setLauncher(Launcher launcher) {
        this.launcher = launcher;
    }
    /**
     * 启动单个组件实例
     *
     * @param context 实例
     */
    public void startComponent(CompInstContext context)  throws  Exception{
        //服务类型独立进程
        //消费类型组件,启动独立线程处理
        logger.debug("-------------》启动组件实例【{}】【{}】【{}】《------", context.getId(), context.getRunMode(), context.getEnv());
        Launcher launcher = getLauncher();
        launcher.start(context);
    }

    /**
     * 停止组件
     *
     * @param context 组件实例ID
     */
    public void stopComponent(CompInstContext context)  throws  Exception{
        //服务类型独立进程
        //消费类型组件,启动独立组件处理
        logger.debug("-------------》停止组件实例【{}】【{}】【{}】《------", context.getId(), context.getRunMode(), context.getEnv());
        Launcher launcher = getLauncher();
        launcher.stop(context);

    }
}
